package com.xatu.yl.storeshopping.service;

import java.util.ArrayList;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

import com.baidu.location.BDAbstractLocationListener;
import com.baidu.location.BDLocation;
import com.xatu.yl.util.baiduGPS.LocationApplication;
import com.xatu.yl.util.baiduGPS.LocationService;
import com.xatu.yl.util.gps.CellInfo;
import com.xatu.yl.storeshopping.AppContent;

public class GpsService extends Service {
    ArrayList<CellInfo> cellIds = null;
    //private Gps gps=null;
    private boolean threadDisable=false;
    //private final static String TAG=GpsService.class.getSimpleName();
    private LocationService locationService;
    @Override
    public void onCreate() {
        super.onCreate();

        //////baiduGPS////////
// -----------location config ------------
        locationService = ((LocationApplication) getApplication()).locationService;
        new Thread(new Runnable(){
            @Override
            public void run() {
                while (true) {
                    try {
                        Thread.sleep(10000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    //LocationService locationService = ((LocationApplication) getApplication()).locationService;
                    //获取locationservice实例，建议应用中只初始化1个location实例，然后使用，可以参考其他示例的activity，都是通过此种方式获取locationservice实例的
                    locationService.start();// 定位SDK


                }
            }
        }).start();
        locationService.setLocationOption(locationService.getDefaultLocationClientOption());
        locationService.registerListener(new BDAbstractLocationListener() {

            @Override
            public void onReceiveLocation(BDLocation location) {
                // TODO Auto-generated method stub
                if (null != location && location.getLocType() != BDLocation.TypeServerError && location.getLatitude()>10) {
                    AppContent.latitude = location.getLatitude()+"";
                    AppContent.longitude = location.getLongitude()+"";
                    AppContent.gpstime = location.getTime();
                    AppContent.gpsHigh = location.getAltitude()+"";
                    AppContent.gpsStatue = "";
                }
            }

        });
        //获取locationservice实例，建议应用中只初始化1个location实例，然后使用，可以参考其他示例的activity，都是通过此种方式获取locationservice实例的
//        locationService.registerListener(new BDAbstractLocationListener() {
//
//            @Override
//            public void onReceiveLocation(BDLocation location) {
//                // TODO Auto-generated method stub
//                if (null != location && location.getLocType() != BDLocation.TypeServerError) {
//                    AppContent.latitude = location.getLatitude()+"";
//                    AppContent.longitude = location.getLongitude()+"";
//                    AppContent.gpstime = location.getTime();
//                    AppContent.gpsHigh = location.getAltitude()+"";
//                    AppContent.gpsStatue = "";
//
//                }
//            }
//
//        });
        //注册监听
//        int type = getIntent().getIntExtra("from", 0);
//        if (type == 0) {
//            locationService.setLocationOption(locationService.getDefaultLocationClientOption());
//        } else if (type == 1) {
//            locationService.setLocationOption(locationService.getOption());
//        }
        //locationService.setLocationOption(locationService.getDefaultLocationClientOption());


        //////baiduGPS////////



    }

    @Override
    public void onDestroy() {

        super.onDestroy();
    }

    @Override
    public IBinder onBind(Intent arg0) {
        return null;
    }


}